using SimpleJSON;

namespace Gj
{
    public enum ComputeAction
    {
        Add,
        Subtract,
        Multiply,
        Divide
    }

    public class ComputeHelper : NodeHelper
    {
        public ComputeAction compute = ComputeAction.Add;
        [SelectRef(UIKey.DATA_KEY)] public SelectKey computeAKey;
        [SelectRef(UIKey.DATA_KEY)] public SelectKey computeBKey;

        protected override BindDataType bindDataType => BindDataType.All;

        protected override void BindData(JSONObject obj)
        {
            if (computeAKey.IsEmpty() || computeBKey.IsEmpty()) return;
            var a = computeAKey.Get(obj).AsFloat;
            var b = computeBKey.Get(obj).AsFloat;
            float value = 0;
            switch (compute)
            {
                case ComputeAction.Add:
                    value = a + b;
                    break;
                case ComputeAction.Subtract:
                    value = a - b;
                    break;
                case ComputeAction.Multiply:
                    value = a * b;
                    break;
                case ComputeAction.Divide:
                    value = a / b;
                    break;
            }

            foreach (var helper in child) helper.SetData(value);
        }
    }
}